package com.example.shop.goods.enums;


/**
 * sql按指定字段排序
 * {@link com.example.shop.pojo.Goods}
 */
public enum GoodsSortRules {
    //根据上架状态排序
    SHELF_STATE("g.shelf_state","shelfState"),
    //根据销量排序
    PURCHASED_TIME("g.purchased_time","purchasedTime"),
    //根据上架时间排序
    SHELF_TIME("g.shelf_time","shelfTime"),
    //根据好评数排序
    FAVORABLE_COMMENT("g.favorable_comment_number","favorableComment"),
    //按分值排序，一定会按分值排序
    RECOMMEND_SCORE("g.recommend_score","recommendScore")
    ;
    public static final String SORT_SQL =
            " " +
            "<if test='ew.sortRules != null and ew.sortRules.getDbField() != \"g.recommend_score\" '>" +
                    "${ew.sortRules.getDbField()},"+
            "</if>" +
            "g.recommend_score" +
            " ";

    private String dbField;
    private String esField;
    GoodsSortRules(String dbField,String esField){
        this.dbField = dbField;
        this.esField = esField;
    }
    public String getDbField(){
       return dbField;
    }

    public String getEsField() {
        return esField;
    }
}
